package com.neuedu.springmvc.framework;

/**
 * 项目：springmvc-java4
 * 创建时间：  2022-03-24   11:35
 * 作者 :jshand
 * 描述 :
 */

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义的异常处理器
 */
@Component
public class MyHandlerExceptionResolver implements HandlerExceptionResolver {


    //统一的处理异常的方法
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
                                         Object handler, Exception ex) {

        ex.printStackTrace();

        request.setAttribute("msg",ex.getMessage());

        ModelAndView mav = new ModelAndView();

        mav.setViewName("/500.jsp");

        return mav;
    }
}
